<!DOCTYPE html>
<html class="um landscape min-width-240px min-width-320px min-width-480px min-width-768px min-width-1024px">
<head>
<title></title>
<meta charset="utf-8">
<meta name="viewport" content="target-densitydpi=device-dpi, width=device-width, initial-scale=1, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<meta name="copyright" content="http://www.appcms.org" />
<link rel="stylesheet" type="text/css" href="skin/base.css">
<link rel="stylesheet" type="text/css" href="skin/form.css">
<link rel="stylesheet" type="text/css" href="skin/editor.css">
<link rel="stylesheet" type="text/css" href="skin/btn.css">
<script src="js/zy_control.js"></script>
<script src="js/zy_json.js"></script>
<script src="js/zy_click.js"></script>
<script src="js/login.js"></script>
<script src="js/config.js"></script>
<script src="js/common.js"></script>
<style>
	.form .pic_c li{};
</style>
</head>
<body>
<div id="main">
	
	<div class="form">
	    	<div class="items">
                 <div class="item" id="type">
		            	<div class="txt"><input placeholder="联系人" type="text" id="contacts" name="contacts"  value=""></div>
		         </div>
				 <div class="item" id="type">
		            	<div class="txt"><input placeholder="联系方式" type="text" id="tel" name="tel"  value=""></div>
		         </div>
		           
		         <div class="item">
		            	<div class="txt">
		            		<textarea id="content" name="content" maxlength="2000" placeholder="报料内容（限2000字）" onkeypress="getRealLen(this.value);" oninput="getRealLen(this.value);"></textarea>
						</div>
		          </div>
	        </div>
                
			<div id="menus">
                <div class="putbtns">
               		
                    <div class="ld pic act" ontouchstart="zy_touch('act')" onclick="btntab('pic');" id="pic_id"></div>
					<div class="ld video" ontouchstart="zy_touch('act')" onclick="btntab('video');" id="video_id"></div>

                    <div class="cd"></div>
                    
                </div>
               
                <ul class="pic_c" id="pic_c_id">
                	<li class="add" ontouchstart="zy_touch('act')" onclick="getpic();" id="add_pic"><div></div></li>
                </ul>
				<ul class="video_c none" id="video_c_id">
                	<li class="add" ontouchstart="zy_touch('act')" onclick="getvideo();" id="add_video"><div></div></li>
                </ul>
               
			</div>
    	</div>
</div>
</body>
<script>
	zy_init();	

	var strlen=0;
	var status=true;
	var uplist = {'pic':{},'video':{}};
	var uplistn=0;


	function getRealLen(str){
    		strlen=str.replace(/[^\x00-\xff]/g,'__').length;
			//$$('words').innerHTML=int(2000-strlen);
			//$$('text').value=substr(str,2000);
	}
	
	function obj2str(obj){
		var _str = '';
		for (var item in obj) {
			_str += obj[item]+'|';
		}
		_str = _str.substr(0, (_str.length - 1));
		return _str;
	}

	function postdata(){
		if (!status) {
			return false;
		}
		status = false;
		
		if (c_l()) {
			var contacts = trim($$('contacts').value) ;
			var tel = trim($$('tel').value);
			var content = trim($$('content').value);
			
			if (content == '') {
				uexWindow.alert('', '忘了写爆料内容了～', '关闭');
				return false;
			}
			if (strlen > 2000) {
				uexWindow.alert('', '报料内容太长了~', '关闭');
				return false;
			}
			
			var url = app_path+'index.php?m=iappBaoliao&c=app&a=baoliaoadd&userid='+localStorage['u_id']+'&acctoken='+localStorage['u_acctoken'];
			uexXmlHttpMgr.open(1,'post',url,"8000");
			uexXmlHttpMgr.setPostData(1,'0','contacts',contacts);
			uexXmlHttpMgr.setPostData(1,'0','tel',tel);
			uexXmlHttpMgr.setPostData(1,'0','content',content);
			
			if(uplist.pic){
				uexXmlHttpMgr.setPostData(1,'0','pic',obj2str(uplist.pic));
			}
			if(uplist.video){
				uexXmlHttpMgr.setPostData(1,'0','video',obj2str(uplist.video));
			}
			
			uexXmlHttpMgr.send(1);
			uexWindow.toast(1, 5, '提交中...', 0);
		}else{
			gologin();
		}
	}
	
	function backrecord(){
		if(!isstart){
			uexAudio.startBackgroundRecord(1);
			isstart = true;
			$$("backrecord").innerHTML = '录音中...';
			$$("backrecordv").innerHTML = '正在录音...';
		}else{
			isstart = false;
			$$("backrecord").innerHTML = '录音完成';
			$$("backrecordv").innerHTML = '录音完成,试听';
			
			uexAudio.stopBackgroundRecord()
			uexAudio.cbBackgroundRecord = function(opId, dataType, data){
				if (dataType == 0) {
					localStorage['talk_ask_voice']=data;
				}
			}
		}
	}
		

	window.uexOnload=function(type){
		if (!type) {
			uexXmlHttpMgr.onData = function(opId, status, data){
				alert(data);
				uexWindow.closeToast();
				uexXmlHttpMgr.close(opId);
				status = true;
				if (status == 1) {
					data = JSON.parse(data);
					if (opId) {
						if (data['success'] == 'NOTLOGIN') {
							gologin();
						}else  if (data['success'] == 'NODATA') {
							uexWindow.toast("0", "5", '参数不能为空', 1000);
						}else if (data['success'] == 'OK') {
								//localStorage['talk_ask_id']=data['id'];
								//uexWindow.evaluatePopoverScript('talk','content','ok_ask()');
								//uexWindow.evaluateScript('talk_ask',0,'uexWindow.close(1)');
							uexWindow.toast("0", "5", '报料成功！', 1000);
						}else {
							uexWindow.toast("0", "5", '报料失败', 1000);
						}
					}
				}else if (status == -1) {
					uexWindow.toast("0", "5", '提交超时', 1000);
				}
			}
		}
	}

	
	/////////////////////////////////////////////////////////////////////
	var sheet = null;
	function createCSS()
	{
		if(!sheet) {
			var style = document.createElement("style");
			document.body.appendChild(style);
			sheet = style.sheet;
		}
		var h =  parseInt(parseInt(window.innerWidth)*0.94/4);
		var pt = parseInt(parseInt(window.innerWidth)*0.06/5);
		var c="height:"+h+"px; margin-top:"+pt+"px;";
		sheet.addRule(".form .pic_c li",c);
	}
	createCSS();
	
	
	
	function btntab(t){
		var arr = ['pic','video']
		for(var k in arr){	
			var a = $$(arr[k]+'_id');
			var b = $$(arr[k]+'_c_id');
			if(arr[k]== t){
				a.className = 'ld '+arr[k]+' act';
				b.className = 'pic_c';
				/*
				if(arr[k] =='pic'){
					getpic();
				}else if(arr[k] =='video'){
					getvideo();
				}
				*/
				
			}else{
				a.className='ld '+arr[k];
				b.className = 'pic_c none';
			}
		}
	}
	
	function getpic(){
		uexWindow.cbActionSheet = function(opId, dt, d){
			var cmd = parseInt(d);
			if(cmd<2){
				if(cmd==1){
					uexImageBrowser.cbPick = function(opCode, dataType, data) {
						uploadImg(data,'pic');
					}
					uexImageBrowser.pick();
				}
				else{
					uexCamera.cbOpen  = function(opCode, dataType, data) {
						uploadImg(data,'pic');
					}
					uexCamera.open(0,80);
				}
			} 
		}
			
		var value = ["拍照上传","本地上传"];
		uexWindow.actionSheet('', '取消', value);
	}

	function uploadImg(dirPath,type){
		uplistn++;
		var pNode = document.getElementById(type+"_c_id");
		var newNode = document.createElement("li");
		newNode.className='uploading';
		newNode.setAttribute("id", type+"_"+uplistn);
		newNode.setAttribute("onclick", "javascript:delNd("+uplistn+",'"+type+"');");
		newNode.setAttribute("ontouchstart", "javascript:zy_touch('act');");

		var reforeNode = document.getElementById("add_"+type);
		pNode.insertBefore(newNode,reforeNode);

		 //上传的状态
	    uexUploaderMgr.onStatus = function(opCode, fileSize, percent, re, status){
	        switch (status) {
	            case 0:
					newNode.innerHTML = '<div>' + percent + "%" + '</div>';
	                break;
	            case 1:
					uexUploaderMgr.closeUploader(1);
					re = JSON.parse(re);
					if (re['success'] == 'OK') {
						newNode.className='';
						newNode.innerHTML ='<div><img src="'+dirPath+'" /></div>';
						uplist[type][type+'_'+uplistn] = re.data;
					}else{
						pNode.removeChild(newNode);
						uexWindow.alert('上传提示', '图片上传失败', '关闭');
					}
	                break;
	            case 2:
	                alert("上传失败");
					pNode.removeChild(newNode);
	                uexUploaderMgr.closeUploader(1);
	                break;
	        }
	    }
		
		//createUploader的回调函数
	    uexUploaderMgr.cbCreateUploader = function(opCode, dataType, data){
	        if (data != 0) {
	            alert("创建上传对象失败！");
				pNode.removeChild(newNode);
				uexUploaderMgr.closeUploader(1);
	        }
	    }
		
		var url = app_path+'index.php?m=iappBaoliao&c=app&a=baoliaoupload&userid='+localStorage['u_id']+'&acctoken='+localStorage['u_acctoken'];
	    //创建一个上传对象
	    uexUploaderMgr.createUploader(1, url);
	    //文件上传
	    uexUploaderMgr.uploadFile(1, dirPath, "photos", 0);
	}
	
	function delNd(id,type){
		uexWindow.cbActionSheet = function(opId, dataType, data)
		{
			if (data == "0") {
				id = parseInt(id);
				removeNode(type+'_'+id);
				delete uplist[type][type+'_'+id];
			}
		}
		var value = ["删除"];
		uexWindow.actionSheet('', '取消', value);
	}

	function getvideo(){
		uexWindow.cbActionSheet = function(opId, dt, wd){
			var cmd = parseInt(wd);
			if(cmd<2){
				if(cmd==1){
					uexFileMgr.cbExplorer = function(opCode, dataType, data){
						alert(data)
						uploadImg(data,'video');
	                }
					uexFileMgr.explorer('');
				}
				else{
					uexVideo.cbRecord = function(opCode, dataType, data){
	                    alert(data);
						uploadImg(data,'video');
	                };
					uexVideo.record();
				}
			} 
		}
		var value = ["拍摄上传","本地上传"];
		uexWindow.actionSheet('', '取消', value);
	}

	</script>
</html>